package com.growthserver.controller;

import com.github.pagehelper.PageInfo;
import com.growthserver.enums.ResultBeans;
import com.growthserver.entity.TMemberDiscountEntity;
import com.growthserver.entity.TMemberEquityEntity;
import com.growthserver.entity.TMemberLevelEntity;
import com.growthserver.param.CommonParam;
import com.growthserver.param.TMemberDiscountParam;
import com.growthserver.param.TMemberEquityParam;
import com.growthserver.param.TMemberLevelParam;
import com.growthserver.service.EquityCenterService;
import com.growthserver.vo.TMemberDiscountVo;
import com.growthserver.vo.TMemberEquityVo;
import com.growthserver.vo.TMemberLevelVo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping(value = "/mp/portal/growth/equityCenter", produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
@Api(description = "权益中心")
public class EquityCenterController {

    @Autowired
    private EquityCenterService equityCenterService;

    /**
     * 会员管理列表展示
     */
    @ApiOperation(value = "会员列表展示",notes = "列表展示,根据type区分展示内容")
    @PostMapping("/memberListDisplay")
//    @ApisInfo(apis= {
//            @GwApiDesc(name = "ly.mp.portal.growth.memberManagement.memberListDisplay", type = ApiType.PORTAL)
//    }, remark = "会员管理--会员列表展示", qps = 100, connectTimeout = 5)
    public ResultBeans<List<TMemberLevelEntity>> memberListDisplay(@RequestBody TMemberLevelParam tMemberLevelParam) {
        ResultBeans<List<TMemberLevelEntity>> result = new ResultBeans<>();
        try {
            List<TMemberLevelEntity> tIovMemberManagementList = equityCenterService.listDisplay(tMemberLevelParam);
            PageInfo<TMemberLevelEntity> tIovMemberManagementPageInfo = new PageInfo<>(tIovMemberManagementList);
            result.setRows(tIovMemberManagementList);
            result.setTotal((int)tIovMemberManagementPageInfo.getTotal());
            result.setResult("1");
            result.setMsg("查询成功");
        } catch (Exception e) {
            result.setResult("0");
            result.setMsg("展示异常");
            result.setRows(new ArrayList<>());
        }
        return result;
    }

    @ApiOperation(value = "权益列表展示",notes = "列表展示,根据type区分展示内容")
    @PostMapping("/equityListDisplay")
//    @ApisInfo(apis= {
//            @GwApiDesc(name = "ly.mp.portal.growth.memberManagement.equityListDisplay", type = ApiType.PORTAL)
//    }, remark = "会员管理--权益列表展示", qps = 100, connectTimeout = 5)
    public ResultBeans<List<TMemberEquityEntity>> equityListDisplay(@RequestBody TMemberEquityParam tMemberEquityParam) {
        ResultBeans<List<TMemberEquityEntity>> result = new ResultBeans<>();
        try {
            List<TMemberEquityEntity> tIovMemberEquities = equityCenterService.equityListDisplay(tMemberEquityParam);
            PageInfo<TMemberEquityEntity> tIovMemberEquityPageInfo = new PageInfo<>(tIovMemberEquities);
            result.setRows(tIovMemberEquities);
            result.setTotal((int)tIovMemberEquityPageInfo.getTotal());
            result.setResult("1");
            result.setMsg("查询成功");
        } catch (Exception e) {
            result.setResult("0");
            result.setMsg("展示异常");
            result.setRows(new ArrayList<>());
        }
        return result;
    }
    @ApiOperation(value = "折扣列表展示",notes = "列表展示,根据type区分展示内容")
    @PostMapping("/discountListDisplay")
//    @ApisInfo(apis= {
//            @GwApiDesc(name = "ly.mp.portal.growth.memberManagement.discountListDisplay", type = ApiType.PORTAL)
//    }, remark = "会员管理--折扣列表展示", qps = 100, connectTimeout = 5)
    public ResultBeans<List<TMemberDiscountEntity>> discountListDisplay(@RequestBody TMemberDiscountParam tMemberDiscountParam) {
        ResultBeans<List<TMemberDiscountEntity>> result = new ResultBeans<>();
        try {
            List<TMemberDiscountEntity> tIovMemberDiscounts = equityCenterService.discountListDisplay(tMemberDiscountParam);
            PageInfo<TMemberDiscountEntity> tIovMemberDiscountPageInfo = new PageInfo<>(tIovMemberDiscounts);
            result.setRows(tIovMemberDiscounts);
            result.setTotal((int)tIovMemberDiscountPageInfo.getTotal());
            result.setResult("1");
            result.setMsg("查询成功");
        } catch (Exception e) {
            result.setResult("0");
            result.setMsg("展示异常");
            result.setRows(new ArrayList<>());
        }
        return result;
    }


    /**
     * 编辑会员管理
     */
    @ApiOperation(value = "编辑会员等级",notes = "编辑会员管理")
    @PostMapping("/updateMember")
//    @ApisInfo(apis= {
//            @GwApiDesc(name = "ly.mp.portal.growth.memberManagement.updateMember", type = ApiType.PORTAL)
//    }, remark = "会员管理--编辑会员等级", qps = 100, connectTimeout = 5)
    public ResultBeans<Object> updateMember(@RequestBody TMemberLevelEntity tMemberLevelEntity,
                                            @RequestHeader(required = false, name = "uid") String uid,
                                            @RequestHeader(required = false, name = "userName") String userName) {
        ResultBeans<Object> result = new ResultBeans<>();
        try {
            tMemberLevelEntity.setModifier(uid);
            tMemberLevelEntity.setModifyName(userName);
            equityCenterService.updateMember(tMemberLevelEntity);
            result.setRows(new ArrayList<>());
            result.setResult("1");
            result.setMsg("编辑会员管理成功");
        } catch (Exception e) {
            result.setResult("0");
            result.setMsg("编辑会员管理失败");
            result.setRows(new ArrayList<>());
        }
        return result;
    }

    /**
     * 编辑会员权益保存
     */
    @ApiOperation(value = "编辑会员权益",notes = "编辑会员权益")
    @PostMapping("/updateEquity")
//    @ApisInfo(apis= {
//            @GwApiDesc(name = "ly.mp.portal.growth.memberManagement.updateEquity", type = ApiType.PORTAL)
//    }, remark = "会员管理--编辑会员权益保存", qps = 100, connectTimeout = 5)
    public ResultBeans<Object> updateEquity(@RequestBody TMemberEquityEntity tMemberEquityEntity,
                                            @RequestHeader(required = false, name = "uid") String uid,
                                            @RequestHeader(required = false, name = "userName") String userName) {
        ResultBeans<Object> result = new ResultBeans<>();
        try {
            tMemberEquityEntity.setModifier(uid);
            tMemberEquityEntity.setModifyName(userName);
            equityCenterService.updateEquity(tMemberEquityEntity);
            result.setRows(new ArrayList<>());
            result.setResult("1");
            result.setMsg("编辑会员权益保存成功");
        } catch (Exception e) {
            result.setResult("0");
            result.setMsg("编辑会员权益保存失败");
            result.setRows(new ArrayList<>());
        }
        return result;
    }

    /**
     * 编辑权益折扣保存
     */
    @ApiOperation(value = "编辑权益折扣",notes = "编辑权益折扣")
    @PostMapping("/updateDiscount")
//    @ApisInfo(apis= {
//            @GwApiDesc(name = "ly.mp.portal.growth.memberManagement.updateDiscount", type = ApiType.PORTAL)
//    }, remark = "会员管理--编辑权益折扣保存", qps = 100, connectTimeout = 5)
    public ResultBeans<Object> updateDiscount(@RequestBody TMemberDiscountEntity tMemberDiscountEntity,
                                              @RequestHeader(required = false, name = "uid") String uid,
                                              @RequestHeader(required = false, name = "userName") String userName) {
        ResultBeans<Object> result = new ResultBeans<>();
        try {
            tMemberDiscountEntity.setModifier(uid);
            tMemberDiscountEntity.setModifyName(userName);
            equityCenterService.updateDiscount(tMemberDiscountEntity);
            result.setRows(new ArrayList<>());
            result.setResult("1");
            result.setMsg("编辑权益折扣保存成功");
        } catch (Exception e) {
            result.setResult("0");
            result.setMsg("编辑权益折扣保存失败");
            result.setRows(new ArrayList<>());
        }
        return result;
    }

    /**
     * 删除数据
     */
    @ApiOperation(value = "删除数据",notes = "删除数据,根据type区分展示内容")
    @PostMapping("/delete")
//    @ApisInfo(apis= {
//            @GwApiDesc(name = "ly.mp.portal.growth.memberManagement.delete", type = ApiType.PORTAL)
//    }, remark = "会员管理--删除数据", qps = 100, connectTimeout = 5)
    public ResultBeans<Object> delete(@RequestBody CommonParam commonParam) {
        ResultBeans<Object> result = new ResultBeans<>();
        try {
            equityCenterService.deleteMember(commonParam);
            result.setRows(new ArrayList<>());
            result.setResult("1");
            result.setMsg("删除数据成功");
        } catch (Exception e) {
            result.setResult("0");
            result.setMsg("删除数据失败");
            result.setRows(new ArrayList<>());
        }
        return result;
    }

    /**
     * 是否启用
     */
    @ApiOperation(value = "是否启用",notes = "删除数据,根据type区分展示内容")
    @PostMapping("/isEnable")
//    @ApisInfo(apis= {
//            @GwApiDesc(name = "ly.mp.portal.growth.memberManagement.isEnable", type = ApiType.PORTAL)
//    }, remark = "会员管理--是否启用", qps = 100, connectTimeout = 5)
    public ResultBeans<Object> isEnable(@RequestBody CommonParam commonParam) {
        ResultBeans<Object> result = new ResultBeans<>();
        try {
            equityCenterService.isEnable(commonParam);
            result.setRows(new ArrayList<>());
            result.setResult("1");
            result.setMsg("是否启用成功");
        } catch (Exception e) {
            result.setResult("0");
            result.setMsg("是否启用失败");
            result.setRows(new ArrayList<>());
        }
        return result;
    }


    /**
     * 会员等级创建
     */
    @ApiOperation(value = "会员等级创建",notes = "会员管理列表展示")
    @PostMapping("/createMemberLvl")
//    @ApisInfo(apis= {
//            @GwApiDesc(name = "ly.mp.portal.growth.memberManagement.createMemberLvl", type = ApiType.PORTAL)
//    }, remark = "会员管理--会员等级创建", qps = 100, connectTimeout = 5)
    public ResultBeans<Object> createMemberLvl(@RequestBody TMemberLevelVo tMemberLevelVo,
                                               @RequestHeader(required = false, name = "uid") String uid,
                                               @RequestHeader (required = false,name = "userName")String userName) {
        ResultBeans<Object> result = new ResultBeans<>();
        try {
            tMemberLevelVo.setCreator(uid);
            tMemberLevelVo.setCreatedName(userName);
            equityCenterService.createMemberLvl(tMemberLevelVo);
            result.setRows(new ArrayList<>());
            result.setResult("1");
            result.setMsg("会员等级创建成功");
        } catch (Exception e) {
            result.setResult("0");
            result.setMsg("会员等级创建失败");
            result.setRows(new ArrayList<>());
        }
        return result;
    }

    /**
     * 会员等级成长值校验
     */
    @ApiOperation(value = "会员等级成长值校验",notes = "会员管理列表展示")
    @PostMapping("/memberLvlCheck")
//    @ApisInfo(apis= {
//            @GwApiDesc(name = "ly.mp.portal.growth.memberManagement.memberLvlCheck", type = ApiType.PORTAL)
//    }, remark = "会员管理--会员等级成长值校验", qps = 100, connectTimeout = 5)
    public ResultBeans<Object> memberLvlCheck(@RequestBody TMemberLevelVo tMemberLevelVo,
                                               @RequestHeader(required = false, name = "uid") String uid,
                                               @RequestHeader (required = false,name = "userName")String userName) {
        ResultBeans<Object> result = new ResultBeans<>();
        try {
            tMemberLevelVo.setCreator(uid);
            tMemberLevelVo.setCreatedName(userName);
            List<TMemberLevelEntity> tMemberLevelEntities = equityCenterService.memberLvlCheck(tMemberLevelVo);
            result.setRows(tMemberLevelEntities);
            result.setResult("1");
            result.setMsg("会员等级成长值校验成功");
        } catch (Exception e) {
            result.setResult("0");
            result.setMsg("会员等级成长值校验失败");
            result.setRows(new ArrayList<>());
        }
        return result;
    }

    /**
     * 会员权益创建
     */
    @ApiOperation(value = "会员权益创建",notes = "会员权益创建")
    @PostMapping("/createMemberEquity")
//    @ApisInfo(apis= {
//            @GwApiDesc(name = "ly.mp.portal.growth.memberManagement.createMemberEquity", type = ApiType.PORTAL)
//    }, remark = "会员管理--会员权益创建", qps = 100, connectTimeout = 5)
    public ResultBeans<Object> createMemberEquity(@RequestBody TMemberEquityVo tMemberEquityVo,
                                                  @RequestHeader(required = false, name = "uid") String uid,
                                                  @RequestHeader (required = false,name = "userName")String userName) {
        ResultBeans<Object> result = new ResultBeans<>();
        try {
            tMemberEquityVo.setCreator(uid);
            tMemberEquityVo.setCreatedName(userName);
            equityCenterService.createMemberEquity(tMemberEquityVo);
            result.setRows(new ArrayList<>());
            result.setResult("1");
            result.setMsg("会员权益创建成功");
        } catch (Exception e) {
            result.setResult("0");
            result.setMsg("会员权益创建失败");
            result.setRows(new ArrayList<>());
        }
        return result;
    }

    /**
     * 会员权益等级区间展示
     */
    @ApiOperation(value = "会员权益等级区间展示",notes = "会员权益等级区间展示")
    @PostMapping("/memberEquityCheck")
//    @ApisInfo(apis= {
//            @GwApiDesc(name = "ly.mp.portal.growth.memberManagement.memberEquityCheck", type = ApiType.PORTAL)
//    }, remark = "会员管理--会员权益等级区间展示", qps = 100, connectTimeout = 5)
    public ResultBeans<Object> memberEquityCheck(@RequestBody TMemberEquityVo tMemberEquityVo,
                                                  @RequestHeader(required = false, name = "uid") String uid,
                                                  @RequestHeader (required = false,name = "userName")String userName) {
        ResultBeans<Object> result = new ResultBeans<>();
        try {
            tMemberEquityVo.setCreator(uid);
            tMemberEquityVo.setCreatedName(userName);
            HashMap<String, Object> objectHashMap = equityCenterService.memberEquityCheck(tMemberEquityVo);
            result.setRows(objectHashMap);
            result.setResult("1");
            result.setMsg("会员权益等级区间展示成功");
        } catch (Exception e) {
            result.setResult("0");
            result.setMsg("会员权益等级区间展示失败");
            result.setRows(new ArrayList<>());
        }
        return result;
    }

    /**
     * 会员折扣创建
     */
    @ApiOperation(value = "会员折扣创建",notes = "会员折扣创建")
    @PostMapping("/createMemberDiscount")
//    @ApisInfo(apis= {
//            @GwApiDesc(name = "ly.mp.portal.growth.memberManagement.createMemberDiscount", type = ApiType.PORTAL)
//    }, remark = "会员管理--会员折扣创建", qps = 100, connectTimeout = 5)
    public ResultBeans<Object> createMemberDiscount(@RequestBody TMemberDiscountVo tMemberDiscountVo,
                                                    @RequestHeader(required = false, name = "uid") String uid,
                                                    @RequestHeader (required = false,name = "userName")String userName) {
        ResultBeans<Object> result = new ResultBeans<>();
        try {
            tMemberDiscountVo.setCreator(uid);
            tMemberDiscountVo.setCreatedName(userName);
            equityCenterService.createMemberDiscount(tMemberDiscountVo);
            result.setRows(new ArrayList<>());
            result.setResult("1");
            result.setMsg("会员折扣创建成功");
        } catch (Exception e) {
            result.setResult("0");
            result.setMsg("会员折扣创建失败");
            result.setRows(new ArrayList<>());
        }
        return result;
    }



    /**
     * 卡级别枚举
     */
    @ApiOperation(value = "卡级别枚举",notes = "权益等级枚举")
    @PostMapping("/equityLvlEnum")
//    @ApisInfo(apis= {
//            @GwApiDesc(name = "ly.mp.portal.growth.memberManagement.equityLvlEnum", type = ApiType.PORTAL)
//    }, remark = "会员管理--卡级别枚举", qps = 100, connectTimeout = 5)
    public ResultBeans<Object> equityLvlEnum(@RequestBody CommonParam commonParam) {
        ResultBeans<Object> result = new ResultBeans<>();
        try {
            List<HashMap<String, String>> list = equityCenterService.equityLvlEnum(commonParam);
            result.setRows(list);
            result.setResult("1");
            result.setMsg("卡级别枚举查询成功");
        } catch (Exception e) {
            result.setResult("0");
            result.setMsg("卡级别枚举查询失败");
            result.setRows(new ArrayList<>());
        }
        return result;
    }

    /**
     * 权益创建等级枚举
     */
    @ApiOperation(value = "权益创建等级枚举",notes = "权益等级枚举")
    @PostMapping("/lvlEnum")
//    @ApisInfo(apis= {
//            @GwApiDesc(name = "ly.mp.portal.growth.memberManagement.lvlEnum", type = ApiType.PORTAL)
//    }, remark = "会员管理--权益创建等级枚举", qps = 100, connectTimeout = 5)
    public ResultBeans<Object> lvlEnum(@RequestBody CommonParam commonParam) {
        ResultBeans<Object> result = new ResultBeans<>();
        try {
            List<HashMap<String, String>> list = equityCenterService.lvlEnum(commonParam);
            result.setRows(list);
            result.setResult("1");
            result.setMsg("权益创建等级枚举查询成功");
        } catch (Exception e) {
            result.setResult("0");
            result.setMsg("权益创建等级枚举查询失败");
            result.setRows(new ArrayList<>());
        }
        return result;
    }

}
